home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8964 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  38 lines

  1. Path: swidir.switch.ch!epflnews!Thomas.Wolf
  2. From: Thomas.Wolf@di.epfl.ch (Thomas Wolf)
  3. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  4. Subject: Re: Access carry flag from C
  5. Date: 27 Feb 1996 17:02:35 GMT
  6. Organization: Ecole Polytechnique FΘdΘrale de Lausanne
  7. Sender: wolf@lglsun5.epfl.ch (Thomas Wolf)
  8. Message-ID: <4gvdfb$qjb@info.epfl.ch>
  9. References: <Dn1C9z.DGv.0.net@indra.com> <n4mwd.40.0010633E@magg.net> <3129DF54.7DC5@hda.hydro.com> <3132f4ea.33276048@netline-fddi.jpl.nasa.gov>
  10. NNTP-Posting-Host: lglsun5.epfl.ch
  11.  
  12. In article <3132f4ea.33276048@netline-fddi.jpl.nasa.gov>, kdq@emoryi.jpl.nasa.gov (Kevin Quitt) writes:
  13. :> On Tue, 20 Feb 1996 15:48:52 +0100, Terje Mathisen
  14. :> <Terje.Mathisen@hda.hydro.com> wrote:
  15. :> >A much more portable solution looks like this:
  16. :> >
  17. :> >unsigned i, j, k;
  18. :> >
  19. :> >  i = j + k;
  20. :> >  if (i < j) /* Overflowed! */ ... ;  // You can also do "if (i < k)" of course!
  21. :> 
  22. :> How can this be portable?  The overflow causes undefined behaviour, so nothing
  23. :> following can be correct.
  24.  
  25. Unsigned arithmetic cannot overflow. The ANSI/ISO standard for the C
  26. programming language defines modulo-arithmetic for unsigned integer types
  27. (ISO/IEC 9899:1990(E), 6.1.2.5, page 23, first paragraph).
  28.  
  29. Regards,
  30.  
  31.   Thomas
  32. ----------------------------------------------------------------------
  33. Swiss Federal Institute of Technology | Thomas Wolf
  34. Software Engineering Laboratory       | EPFL-DI-LGL
  35. Thomas Wolf (TW)                      | CH-1015 Lausanne (Suisse)
  36. E-Mail: wolf@di.epfl.ch               | Phone: (++41 21)693 42 37
  37. ---------------------------------------------------------------------- 
  38.